<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<style>
    /*重新设置样式*/
    .form-control {
        width: 196px !important;
        height: 34px !important;
        padding: 10px !important;
    }
</style>
<body class="hold-transition skin-blue sidebar-mini"  onload="checkBrowser()">
<section class="content-header">
    <h1 style="display: inline-block" id="title">创建串料申请</h1>
    <button onclick="javascript:window.history.back();" type="button" class="btn btn-success"
            style="text-align:center;vertical-align:middle;font-size:30px;position:absolute;right:3%;display: inline-block;background-color: transparent;border: none;color: #5c5c5c;outline:none;">
        <i style="-moz-transform:scaleX(-1);-webkit-transform:scaleX(-1);-o-transform:scaleX(-1);transform:scaleX(-1);filter:FlipH;"
           class="glyphicon glyphicon-share-alt"></i><span
            style="margin-left: 5px;font-size: 16px;position: absolute;top: 20%;">返回</span>
    </button>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header" style="text-align: center">
                    <h3>串料申请基本信息</h3>
                </div>
                <div class="box-body" style="text-align: center">
                    <div class="col-md-10 col-md-offset-1" style="text-align: left">
                        <form id="changeOrderForm" method="post" class="form-horizontal" role="form"
                              enctype="multipart/form-data">
                            <div hidden>
                                <input name="ceoUseItyId">
                                <input name="mode" th:value="${mode}">
                                <input name="ceoId" th:value="${ceoId}">
                            </div>
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group" style="height: 50px;">
                                        <label for="ceoNeedProCode" class="col-sm-3 control-label"
                                               style="width: 150px;text-align: right">
                                            需求项目编号
                                        </label>
                                        <div class="col-sm-7">
                                            <input class="form-control" list="ceoNeedProCodeList"
                                                   onchange="changeCeoNeedProName()"
                                                   oninput="findProCodeListData(this)"
                                                   name="ceoNeedProCode"
                                                   id="ceoNeedProCode"
                                                   autocomplete="off"
                                                   type="text"
                                                   placeholder="请输入需求项目编号"/>
                                            <datalist id="ceoNeedProCodeList">
                                            </datalist>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group" style="height: 50px;">
                                        <label class="col-sm-3 control-label" style="width: 150px;text-align: right">
                                            挪用项目编号
                                        </label>
                                        <div class="col-sm-6">
                                            <input class="form-control" name="ceoUseProCode"
                                                   type="text"
                                                   readonly="readonly"/>
                                        </div>
                                        <div class="col-sm-2" th:if="${mode!='see'}">
                                            <button style="margin-left: 10px" type="button" class="btn btn-info"
                                                    id="btn_select"
                                                    onclick="selectInventory()">
                                                选择
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group" style="height: 50px;">
                                        <label class="col-sm-3 control-label" style="width: 150px;text-align: right">
                                            需求项目名称
                                        </label>
                                        <div class="col-sm-7">
                                            <input class="form-control" name="ceoNeedProName" type="text"
                                                   placeholder="请输入需求项目编号"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group" style="height: 50px;">
                                        <label class="col-sm-3 control-label" style="width: 150px;text-align: right">
                                            挪用项目名称
                                        </label>
                                        <div class="col-sm-7">
                                            <input class="form-control" name="ceoUseProName" type="text"
                                                   readonly="readonly"/>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group" style="height: 50px;">
                                        <label class="control-label col-sm-3"
                                               style="width: 150px;text-align: right">
                                            需求物料描述
                                        </label>
                                        <div class="col-sm-7">
                                            <input class="form-control" name="ceoNeedMatName" type="text"

                                                   placeholder="请输入需求物料描述"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group" style="height: 50px;">
                                        <label class="col-sm-3 control-label" style="width: 150px;text-align: right">
                                            挪用物料描述
                                        </label>
                                        <div class="col-sm-7">
                                            <input class="form-control" name="ceoUseMatName" type="text"
                                                   readonly="readonly"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group" style="height: 50px;">
                                        <label class="control-label col-sm-3" style="width: 150px;text-align: right">
                                            需求数量
                                        </label>
                                        <div class="col-sm-4">
                                            <input class="form-control" name="ceoNeedNum" oninput="checkValue(this)"
                                                   type="text" id="ceoNeedNum"
                                                   style="text-align: right;width: 150px!important;"
                                                   placeholder="请输入需求数量"/>
                                        </div>
                                        <div class="col-sm-2" style="padding: 0px;margin: 0px">
                                            <input style="background-color: white;border: 0px;color: black"
                                                   class="form-control" name="ceoNeedUnit" id="ceoNeedUnit" type="text"
                                                   readonly="readonly"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group" style="height: 50px;">
                                        <label class="control-label col-sm-3" style="width: 150px;text-align: right">
                                            可用数量
                                        </label>
                                        <div class="col-sm-4">
                                            <input class="form-control" name="ceoUseNum"
                                                   style="text-align: right;width: 150px!important;"
                                                   type="text" id="ceoUseNum"
                                                   readonly="readonly"/>
                                        </div>
                                        <div class="col-sm-2" style="padding: 0px;margin: 0px">
                                            <input style="background-color: white;border: 0px;color: black"
                                                   class="form-control" name="ceoUseUnit" id="ceoUseUnit" type="text"
                                                   readonly="readonly"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!--<div class="row">-->
                            <!--<div class="col-md-6" style="height: 50px;">-->
                            <!--<div class="form-group">-->
                            <!--<label class="control-label col-sm-3" style="width: 150px;text-align: right">-->
                            <!--使用部门-->
                            <!--</label>-->
                            <!--<div class="col-sm-7" style="text-align: left">-->
                            <!--<select name="ceoNeedDepId" id="ceoNeedDepId"-->
                            <!--style="padding: 0px!important;text-align: center!important;text-align-last: center!important;"-->
                            <!--class="form-control select"></select>-->
                            <!--</div>-->
                            <!--</div>-->
                            <!--</div>-->
                            <!--<div class="col-md-6" style="height: 50px;">-->
                            <!--<div class="form-group">-->
                            <!--<label class="control-label col-sm-3" style="width: 150px;text-align: right">-->
                            <!--所在部门-->
                            <!--</label>-->
                            <!--<div class="col-sm-7">-->
                            <!--<select name="ceoUseDepId" id="ceoUseDepId" class="form-control select"-->
                            <!--style="padding: 0px!important;text-align: center!important;text-align-last: center!important;"></select>-->
                            <!--</div>-->
                            <!--</div>-->
                            <!--</div>-->
                            <!--</div>-->
                            <div class="row">
                                <div class="col-md-6" hidden>
                                    <div class="form-group" style="height: 50px;">
                                        <label class="control-label col-sm-3"
                                               style="width: 150px;text-align: right;background-color: #FFFFFF">
                                            是否需要还料
                                        </label>
                                        <div style="margin: 0px;padding: 0px 5px 0px 0px;text-align: right"
                                             class="col-sm-1">
                                            <input class="form-radio" name="ceoIfRet" id="ceoIfRet1" value="1"
                                                   style="margin: 0px;margin: 8px 0px 0px 0px;"
                                                   type="radio"/>
                                        </div>
                                        <label class="col-sm-2" for="ceoIfRet1"
                                               style="margin: 0px;padding: 5px 0px 0px 0px;">
                                            需要
                                        </label>
                                        <div style="margin: 0px;padding: 0px 5px 0px 0px ;text-align: right"
                                             class="col-sm-1">
                                            <input class="form-radio" name="ceoIfRet" id="ceoIfRet2" value="2"
                                                   style="margin: 0px;margin: 8px 0px 0px 0px;"
                                                   type="radio" checked="checked"/>
                                        </div>
                                        <label class="col-sm-2" for="ceoIfRet2"
                                               style="margin: 0px;padding: 5px 0px 0px 0px;">
                                            不需要
                                        </label>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group" style="height: 50px;">
                                        <label class="control-label col-sm-3" style="width: 150px;text-align: right">
                                            物料所在仓库
                                        </label>
                                        <div class="col-sm-7" style="padding-right: 0px;padding-right: 0px">
                                            <select name="ceoUseWhiId" readonly="readonly"
                                                    class="form-control select" onmousedown="javascript:return false;"
                                                    style="padding: 0px!important;text-align: center!important;text-align-last: center!important;width: auto!important;">
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group" style="height: 50px;">
                                        <label class="col-sm-3"
                                               style="text-align: right;width: 150px;text-align: right;">
                                            物料所在区位
                                        </label>
                                        <div class="col-sm-7" data-dismiss="padding-right: 0px;padding-right: 0px">
                                            <input class="form-control" name="ceoUsePosition" type="text"
                                                   readonly="readonly"
                                                   style="text-align: right">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group" style="height: 50px;">
                                        <label class="control-label col-sm-3" style="width: 150px;text-align: right">
                                            需求项目生产状况
                                        </label>
                                        <div class="col-sm-7">
                                            <input class="form-control"
                                                   name="ceoNeedStatus"
                                                   type="text" maxlength="125"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group" style="height: 50px;">
                                        <label class="control-label col-sm-3" style="width: 150px;text-align: right">
                                            挪用项目生产状况
                                        </label>
                                        <div class="col-sm-7">
                                            <input class="form-control"
                                                   name="ceoUseStatus"
                                                   type="text" maxlength="125"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group" style="height: 50px;">
                                        <label class="control-label col-sm-3" style="width: 150px;text-align: right">
                                            需求项目标准号
                                        </label>
                                        <div class="col-sm-7">
                                            <input class="form-control"
                                                   name="ceoNeedStandardNo"
                                                   type="text" maxlength="125"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="form-group" style="height: 130px;">
                                        <label class="control-label col-sm-3" style="width: 150px;text-align: right">
                                            备注
                                        </label>
                                        <div class="col-sm-9">
                                            <textarea class="form-control"
                                                      style="width: 887px!important;height: 125px!important;"
                                                      name="ceoRemark"
                                                      placeholder="请输入备注" rows="5"
                                                      cols="100"></textarea>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group" style="height: 50px;">
                                        <label class="control-label col-sm-3" style="width: 150px;text-align: right">
                                            申请人
                                        </label>
                                        <div class="col-sm-7">
                                            <input class="form-control" th:value="${ceoAppPerson}"
                                                   name="ceoAppPerson"
                                                   type="text"
                                                   readonly="readonly"/>
                                            <input class="form-control" th:value="${ceoAppPersonId}"
                                                   name="ceoAppPersonId"
                                                   type="hidden"
                                                   readonly="readonly"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group" style="height: 50px;">
                                        <label class="control-label col-sm-3" style="width: 150px;text-align: right">
                                            申请日期
                                        </label>
                                        <div class="col-sm-7">
                                            <input class="form-control" th:value="${ceoAppDate}" name="ceoAppDate"

                                                   type="text"
                                                   readonly="readonly"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row" th:if="${mode!='see'}" shiro:hasPermission="purinv:purchalist:edit">
                                <div class="col-sm-12" style="text-align: right;vertical-align: middle">
                                    <button class="btn btn-success" style="border: #1295bf 2px solid" type="button"
                                            id="btn_save">保存
                                    </button>
                                    <button style="margin-left: 30px" class="btn btn-primary" type="button"
                                            id="btn_reset">重置表单
                                    </button>
                                    <button style="margin-left: 30px" class="btn btn-success" type="button"
                                            id="btn_verification">再次验证
                                    </button>
                                </div>

                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<!--选择外购件库存模态框-->
<div class="modal fade" id="modal-select-purchase">
    <div class="modal-dialog" style="width: 1400px;">
        <div class="modal-content">
            <div class="modal-header" style="padding-bottom: 0px;">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">外购件库在库明细信息</h4>
            </div>
            <div class="modal-body" style="padding-bottom: 5px;padding-top: 0px;">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box">
                            <div class="box-header" style="padding-bottom: 0px;">
                                <form id="modalQueryForm">
                                    <div class="row" id="HiddenDiv">
                                        <div class="form-inline">
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                                <label>
                                                    物料描述
                                                </label>
                                                <input type="text" id="ityMatDesc" name="ityMatDesc"
                                                       class="form-control"
                                                       placeholder="请输入物料描述">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                                <label>
                                                    SAP物料编码
                                                </label>
                                                <input type="text" id="itySapCode" name="itySapCode"
                                                       class="form-control"
                                                       placeholder="请输入物料编码">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                                <label>项目名称</label>
                                                <input type="text" id="ityProName" name="ityProName"
                                                       class="form-control"
                                                       placeholder="请输入项目名称">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                                <label>项目编号</label>
                                                <input type="text" id="ityProCode" name="ityProCode"
                                                       class="form-control"
                                                       placeholder="请输入项目编号">
                                            </div>

                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                                <label>跟踪号</label>
                                                <input type="text" id="ityTrackCode" name="ityTrackCode"
                                                       class="form-control"
                                                       placeholder="请输入跟踪号">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                                <label>
                                                    生产状态
                                                </label>
                                                <select id="proProductionStatus"
                                                        name="proProductionStatus"
                                                        class="form-control"
                                                        style="padding: 0px!important;text-align: center!important;text-align-last: center!important;">
                                                    <option value="" selected="selected">全部</option>
                                                    <option value="-1">无状态</option>
                                                    <option value="1">未开始</option>
                                                    <option value="2">执行中</option>
                                                    <option value="3">已完成</option>
                                                    <option value="4">取消</option>
                                                    <option value="5">暂缓</option>
                                                </select>
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                                <label>
                                                    区位
                                                </label>
                                                <input type="text" id="ityPosition" name="ityPosition"
                                                       class="form-control"
                                                       placeholder="请输入区位">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                                <label>仓库</label>
                                                <select id="ityWhiId" class="form-control select" name="ityWhiId"
                                                        style="padding: 0px!important;text-align: center!important;text-align-last: center!important;">
                                                </select>
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>是否串料</label>
                                                <select style="padding: 0px!important;text-align: center!important;text-align-last: center!important;width: auto!important;"
                                                        class="form-control select"
                                                        name="ityChangeFlag">
                                                    <option value="">全部</option>
                                                    <option value="100">是</option>
                                                    <option value="1">串入</option>
                                                    <option value="2">串出</option>
                                                    <option value="3">先入后出</option>
                                                    <option value="200">否</option>
                                                </select>
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                                <button type="button" class="btn btn-success" id="btn_inventorySearch">
                                                    搜索
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="box-body"
                                 style="padding-top: 0px;padding-bottom: 0px;height: 670px">
                                <table id="inventoryQueryTable" class="table table-bordered " width="100%"
                                       data-height="670">
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer" style="padding-top: 5px;">
            </div>
        </div>
    </div>

</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var table;
    var modalTable;
    var statusText = ["无状态", "执行中", "未开始", "暂缓", "已完成", "取消"];
    var proStatusText = ["无状态", "执行中", "未开始", "暂缓", "已完成", "取消"];

    function checkBrowserFun() {
        let is360 = false;
        let isIE = false;
        let isFirefox = false;
        let isChrome = false;
        let isEdge = false;
        let broName = 'Runing';
        let str = '';
        let strStart = 0;
        let strStop = 0;
        let arr = new Array();
        let temp = '';
        let userAgent = window.navigator.userAgent; //包含以下属性中所有或一部分的字符串：appCodeName,appName,appVersion,language,platform
        /*alert(userAgent);*/
        //FireFox
        if (userAgent.indexOf('Firefox') != -1) {
            isFireFox = true;
            /*broName = 'FireFox浏览器';*/
            strStart = userAgent.indexOf('Firefox');
            temp = userAgent.substring(strStart);
            broName = temp.replace('/', '版本号')

        }
        //Edge
        if (userAgent.indexOf('Edge') != -1) {
            isEdge = true;
            /*broName = 'Edge浏览器';*/
            strStart = userAgent.indexOf('Edge');
            temp = userAgent.substring(strStart);
            broName = temp.replace('/', '版本号');
        }
        //IE浏览器
        if (userAgent.indexOf('NET') != -1 && userAgent.indexOf("rv") != -1) {
            isIE = true;
            /*broName = 'IE浏览器'; */
            strStart = userAgent.indexOf('rv');
            strStop = userAgent.indexOf(')');
            temp = userAgent.substring(strStart, strStop);
            broName = temp.replace('rv', 'IE').replace(':', '版本号');
        }
        //360极速模式可以区分360安全浏览器和360极速浏览器
        if (userAgent.indexOf('WOW') != -1 && userAgent.indexOf("NET") < 0 && userAgent.indexOf("Firefox") < 0) {
            if (navigator.javaEnabled()) {
                is360 = true;
                broName = '360安全浏览器-极速模式';
            } else {
                is360 = true;
                broName = '360极速浏览器-极速模式';
            }
        }
        //360兼容
        if (userAgent.indexOf('WOW') != -1 && userAgent.indexOf("NET") != -1 && userAgent.indexOf("MSIE") != -1 && userAgent.indexOf("rv") < 0) {
            is360 = true;
            broName = '360兼容模式';
        }
        //Chrome浏览器
        if (userAgent.indexOf('WOW') < 0 && userAgent.indexOf('Chrome') > 0 && userAgent.indexOf("Edg") < 0) {
            isChrome = true;
            /*broName = 'Chrome浏览器';*/
            strStart = userAgent.indexOf('Chrome');
            strStop = userAgent.indexOf(' Safari');
            temp = userAgent.substring(strStart, strStop);
            broName = temp.replace('/', '版本号');
        }
        return isChrome;
    }

    /**
     * 检测浏览器
     * */
    function checkBrowser(){
        if(!checkBrowserFun()){
            js.modal.warning("尊敬的客户，您使用浏览器不是谷歌浏览器，请使用谷歌浏览器访问本系统！");
            location.href=ctx+"overview/index";
        }
    }


    /**
     *@FunctionName: checkValue
     *@Description: 检测控制其值不可大于库存可用数量，只能输入两位小数
     *@Author: 徐一贺
     *@CreateDate: 2020/4/21 19:23
     *@Phone: 18241927380
     *@Param:
     *@Return:
     *@Version: v 1.0.0
     */
    function checkValue(obj) {
        obj.value = obj.value.replace(/[^\d.]/g, "");  //清除“数字”和“.”以外的字符
        obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
        obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
        obj.value = obj.value.replace(/^(\d+)\.(\d\d\d).*$/, '$1$2');//只能输入两个小数
        if (obj.value.indexOf(".") < 0 && obj.value != "") {//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
            obj.value = obj.value;
        }
        // var compareValue = $("#changeOrderForm [name='ceoUseNum']").val();
        // if (compareValue != undefined && compareValue != null && compareValue != '') {
        //     // if (Number($(obj).val()) > Number(compareValue)) {
        //     //     $(obj).val(compareValue);
        //     // }
        // } else {
        //     js.modal.alert('请选择库存！');
        //     $(obj).val('');
        //     $(obj).focus();
        // }
    }


    /**
     *@FunctionName: loadDept
     *@Description: 获取部门下拉框内容
     *@Author: 徐一贺
     *@CreateDate: 2020/4/21 19:16
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function loadDept() {
        $("title").html($("title").html()+" —— 创建串料单");
        $.post(ctx + 'purWarOutManage/findDeptList',
            {},
            function (res) {
                if (res.type == 'SUCCESS') {
                    $("#changeOrderForm [name='ceoNeedDepId']").empty();
                    $("#changeOrderForm [name='ceoUseDepId']").empty();
                    $("#changeOrderForm [name='ceoNeedDepId']").append('<option value="">请选择使用部门</option>');
                    $("#changeOrderForm [name='ceoUseDepId']").append('<option value="">请选择所在部门</option>');
                    for (var i = 0; i < res.data.length; i++) {
                        $("#changeOrderForm [name='ceoNeedDepId']").append('<option value="' + res.data[i].depId + '">' + res.data[i].depName + '</option>');
                        $("#changeOrderForm [name='ceoUseDepId']").append('<option value="' + res.data[i].depId + '">' + res.data[i].depName + '</option>');
                    }
                    // $("#changeOrderForm [name='ceoNeedStatus']").empty();
                    // $("#changeOrderForm [name='ceoNeedStatus']").append('<option value="">请输入需求项目编号</option>');
                    // $("#changeOrderForm [name='ceoNeedStatus']").append('<option value="1">制作中</option>');
                    // $("#changeOrderForm [name='ceoNeedStatus']").append('<option value="2">待制作</option>');
                    // $("#changeOrderForm [name='ceoNeedStatus']").append('<option value="3">暂缓</option>');
                    // $("#changeOrderForm [name='ceoNeedStatus']").append('<option value="4">完成</option>');
                    // $("#changeOrderForm [name='ceoUseStatus']").empty();
                    // $("#changeOrderForm [name='ceoUseStatus']").append('<option value="">请选择库存</option>');
                    // $("#changeOrderForm [name='ceoUseStatus']").append('<option value="1">制作中</option>');
                    // $("#changeOrderForm [name='ceoUseStatus']").append('<option value="2">待制作</option>');
                    // $("#changeOrderForm [name='ceoUseStatus']").append('<option value="3">暂缓</option>');
                    // $("#changeOrderForm [name='ceoUseStatus']").append('<option value="4">完成</option>');
                    $.post(ctx + 'purchase/change/getChangeOrder', {
                        ceoIds: $("#changeOrderForm [name='ceoId']").val()
                    }, function (result) {
                        if (result.type == 'SUCCESS') {
                            if (result.data != undefined || result.data != null) {
                                $("#changeOrderForm [name='ceoUseProCode']").val(result.data.ceoUseProCode);
                                $("#changeOrderForm [name='ceoNeedProCode']").val(result.data.ceoNeedProCode);
                                $("#changeOrderForm [name='ceoUseProName']").val(result.data.ceoUseProName);
                                $("#changeOrderForm [name='ceoNeedProName']").val(result.data.ceoNeedProName);
                                $("#changeOrderForm [name='ceoUseMatName']").val(result.data.ceoUseMatName);
                                $("#changeOrderForm [name='ceoNeedMatName']").val(result.data.ceoNeedMatName);
                                $("#changeOrderForm [name='ceoNeedStandardNo']").val(result.data.ceoNeedStandardNo);
                                $("#changeOrderForm [name='ceoRemark']").val(result.data.ceoRemark);
                                $("#changeOrderForm [name='ceoUseNum']").val(result.data.ceoUseNum);
                                $("#changeOrderForm [name='ceoNeedNum']").val(result.data.ceoNeedNum);
                                $("#changeOrderForm [name='ceoUseItyId']").val(result.data.ceoUseItyId);
                                $("#changeOrderForm [name='ceoUseUnit']").val(result.data.ceoUseUnit);
                                $("#changeOrderForm [name='ceoNeedUnit']").val(result.data.ceoNeedUnit);
                                $("#changeOrderForm [name='ceoUseWhiId']").val(result.data.ceoUseWhiId);
                                $("#changeOrderForm [name='ceoNeedDepId']").val(result.data.ceoNeedDepId);
                                $("#changeOrderForm [name='ceoUseDepId']").val(result.data.ceoUseDepId);
                                $("#changeOrderForm [name='ceoUsePosition']").val(result.data.ceoUsePosition);
                                if (result.data.ceoIfRet == 1) {
                                    $("#changeOrderForm [name='ceoIfRet'][value='1']").attr("checked", "checked");
                                }
                                if (result.data.ceoIfRet == 2) {
                                    $("#changeOrderForm [name='ceoIfRet'][value='2']").attr("checked", "checked");
                                }
                                $("#changeOrderForm [name='ceoUseStatus']").val(result.data.ceoUseStatus);
                                $("#changeOrderForm [name='ceoNeedStatus']").val(result.data.ceoNeedStatus);
                            }
                            var mode = $("#changeOrderForm [name='mode']").val();
                            switch (mode) {
                                //查看
                                case "see":
                                    $("#title").html("串料申请查看");
                                    $('#ceoNeedDepId').attr('readonly', 'readonly');
                                    $('#ceoNeedDepId').attr('onmousedown', 'javascript:return false;');
                                    $('#ceoUseDepId').attr('readonly', 'readonly');
                                    $('#ceoUseDepId').attr('onmousedown', 'javascript:return false;');
                                    $('#ceoUseDepId').attr('readonly', 'readonly');
                                    $("#changeOrderForm [name='ceoUseWhiId']").attr('onmousedown', 'javascript:return false;');
                                    $("#changeOrderForm [name='ceoIfRet']").attr('onClick', 'javascript:return false ');
                                    $('#changeOrderForm').find('input,textarea,select').prop('readonly', true);
                                    break;
                                //编辑
                                case "edit":
                                    $("#title").html("串料申请编辑");
                                    break;
                                default:
                                    break;
                            }
                        }
                    }, 'json')
                }
            }, 'json');
    }


    /**
     *@FunctionName: selectInventory
     *@Description: 选择库存
     *@Author: 徐一贺
     *@CreateDate: 2020/4/16 9:27
     *@Phone: 18241927380
     *@Param:
     *@Return:
     *@Version:
     */
    function selectInventory() {
        $('#inventoryQueryTable').bootstrapTable('destroy');
        modalTable = js.table.init({
            id: 'inventoryQueryTable',
            url: ctx + "purchase/change/inventoryList",
            // sortable: true,                                    // 是否启用排序
            // sortStable: true,                                  // 设置为 true 将获得稳定的排序
            // showColumns: true,
            showExport: false,
            queryForm: 'modalQueryForm',
            pageSize: 15,
            onLoadSuccess: function () {
                $("#btn_inventorySearch").prop('disabled', false).removeClass('disabled');
                $('#inventoryQueryTable thead th').each(function () {
                    $(this).width(Math.floor($(this).width()));
                });
                $('#inventoryQueryTable tbody tr:first td').each(function () {
                    $(this).width(Math.floor($(this).width()));
                });
            },
            columns: [
                {
                    title: '序号', field: 'ityId', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {
                    title: '串料标识', field: 'ityChangeFlag', formatter: function (value, row, index) {
                        if (value == undefined || value == null) {
                            return "";
                        } else {
                            var text = "";
                            var labelClass = "";
                            switch (value) {
                                case 1:
                                    text = "串入"
                                    labelClass = "badge label-success";
                                    break;
                                case 2:
                                    text = "串出"
                                    labelClass = "badge label-danger";
                                    break;
                                case 3:
                                    text = "先入后出"
                                    labelClass = "badge label-warning";
                                    break;
                                default:
                                    return "";
                            }
                            return '<label class="' + labelClass + '">' + text + '</label>';
                        }
                    }
                },
                {title: 'SAP<br>物料编码', field: 'itySapCode', width: '120'},
                {title: '物料描述', field: 'ityMatDesc', width: '200'},
                {title: '可用数量', field: 'ityAvaNum', sortable: true},
                {title: '单位', field: 'ityNumUnit', width: '50'},
                {
                    title: '项目编号', field: 'ityProCode', formatter: function (value, row, index) {
                        if (value == undefined || value == null) {
                            value = "--";
                        }
                        return value;
                    }
                },
                {
                    title: '项目名称', field: 'ityProName', width: '200', formatter: function (value, row, index) {
                        if (value == undefined || value == null) {
                            value = "--";
                        }
                        return value;
                    }
                },
                {title: '跟踪号', field: 'ityTrackCode'},
                {
                    title: '生产状态', field: 'proProductionStatus',
                    formatter: function (value, row, index) {
                        if (value == undefined || value == null) {
                            value = 0;
                        }
                        return statusText[value];
                    }
                },
                {
                    title: '备注', field: 'ityRemark',
                    formatter: function (value, row, index) {
                        if (value == undefined || value == null) {
                            return "";
                        }
                        return value;
                    }
                },
                {title: '仓库', field: 'whiName'},
                {title: '区位', field: 'ityPosition'},
                {
                    title: '在库类型', field: 'ityStockType',
                    formatter: function (value, row, index) {
                        var ityStockType = "";
                        if (value == 1) {
                            ityStockType = "库存在库";
                        } else if (value == 2) {
                            ityStockType = "项目在库";
                        }
                        return ityStockType;
                    }
                },
                {
                    title: '  操作',
                    width: '80',
                    field: 'ityDataStatus',
                    formatter: function (value, row, index) {
                        if (hasP("purinv:purchalist:edit")) {
                            var ityDataStatus = "";
                            if (value == 2) {
                                ityDataStatus = 'disabled';
                            } else {
                                ityDataStatus = '';
                            }
                            return '<button class="btn btn-success" ' + ityDataStatus + ' onclick="selectInventoryToChange(' + row.ityId + ')" type="button" >选择</button>';
                        }
                    }
                }
            ]
        });
        js.modal.open("modal-select-purchase");

    }

    /**
     *@FunctionName: selectInventoryToChange
     *@Description: 选择
     *@Author: 徐一贺
     *@CreateDate: 2020/4/16 10:43
     *@Phone: 18241927380
     *@Param: [ityId]库存主键
     *@Version: 1.0.0
     */
    function selectInventoryToChange(ityId) {
        $.post(ctx + 'purchase/change/getPInventory', {
                ceoUseItyId: ityId
            },
            function (result) {
                if (result.type == 'SUCCESS') {
                    $("#changeOrderForm [name='ceoUseProCode']").val(result.data.ceoUseProCode);
                    $("#changeOrderForm [name='ceoUseProName']").val(result.data.ceoUseProName);
                    $("#changeOrderForm [name='ceoUseMatName']").val(result.data.ceoUseMatName);
                    $("#changeOrderForm [name='ceoNeedMatName']").val(result.data.ceoUseMatName);
                    $("#changeOrderForm [name='ceoUseNum']").val(result.data.ceoUseNum);
                    $("#changeOrderForm [name='ceoUseItyId']").val(result.data.ceoUseItyId);
                    $("#changeOrderForm [name='ceoUseNum']").val(result.data.ceoUseNum);
                    $("#changeOrderForm [name='ceoUseUnit']").val(result.data.ceoUseUnit);
                    $("#changeOrderForm [name='ceoNeedUnit']").val(result.data.ceoNeedUnit);
                    $("#changeOrderForm [name='ceoUseWhiId']").val(result.data.ceoUseWhiId);
                    $("#changeOrderForm [name='ceoUsePosition']").val(result.data.ceoUsePosition);
                    $("#changeOrderForm [name='ceoUseStatus']").val(result.data.ceoUseStatus);
                    js.modal.hide("modal-select-purchase");
                    search();
                }
            }, 'json');
    }
    /**
     *@FunctionName: findWarehouseList
     *@Description: 获取仓库列表
     *@Author: 徐一贺
     *@CreateDate: 2020/3/24 15:31
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function findWarehouseList() {
        js.ajax({
            url: ctx + 'common/warehouseInfo/list',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {},
            async: false,                // 异步执行
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    $('#ityWhiId').empty();
                    $('#ityWhiId').append('<option value="">全部</option>');
                    $("#changeOrderForm [name='ceoUseWhiId']").empty();
                    $("#changeOrderForm [name='ceoUseWhiId']").append('<option value="">请选择库存</option>');
                    for (var i = 0; i < result.data.rows.length; i++) {
                        $('#ityWhiId').append('<option value="' + result.data.rows[i].whiId + '">' + result.data.rows[i].whiName + '</option>');
                        $("#changeOrderForm [name='ceoUseWhiId']").append('<option value="' + result.data.rows[i].whiId + '">' + result.data.rows[i].whiName + '</option>');
                    }
                } else {
                    js.modal.warning(result.msg);
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }


    /**
     *@FunctionName: search
     *@Description: 查询
     *@Author: 徐一贺
     *@CreateDate: 2020/4/10 16:10
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function search() {
        js.table.search(table);
    }

    /**
     *@FunctionName: selectAll
     *@Description: 全选
     *@Author: 徐一贺
     *@CreateDate: 2020/4/8 15:20
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function selectAll(obj) {

        $('input[name="cb_inventory"]').each(function () {
            if (!$(this).prop("disabled")) {
                if ($(obj).prop("checked")) {
                    $(this).prop("checked", true);
                }
                if ($(obj).prop("checked") == false) {
                    $(this).prop("checked", false);
                }
            }
        })

    }

    /**
     *@FunctionName: findProCodeListData
     *@Description: 根据项目号模糊查询获取项目号列表
     *@Author: 徐一贺
     *@CreateDate: 2020/4/18 12:59
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function findProCodeListData(obj) {

        $.post(ctx + 'purchase/change/findProCodeList', {
            code: $(obj).val()
        }, function (result) {
            if (result.type == 'SUCCESS') {
                $("#ceoNeedProCodeList").empty();
                for (var i = 0; i < result.data.length; i++) {
                    $("#ceoNeedProCodeList").append('<option value="' + result.data[i].code + '" data="' + result.data[i].name + '" data-status="' + result.data[i].status + '">' + result.data[i].name + '</option>');
                }
                obj.val(obj.val().toUpperCase());
            }
        }, 'json');
    }

    function changeCeoNeedProName() {
        var input_select = $("#changeOrderForm [name='ceoNeedProCode']").val();
        var option_length = $("#ceoNeedProCodeList").find("option").length;
        for (var i = 0; i < option_length; i++) {
            if (input_select == $("#ceoNeedProCodeList option").eq(i).attr('value')) {
                $("#changeOrderForm [name='ceoNeedProName']").val($("#ceoNeedProCodeList option").eq(i).attr("data"));
                var proStatus = $("#ceoNeedProCodeList option").eq(i).attr("data-status");
                if (proStatus == undefined || proStatus == null || proStatus == 'undefined') {
                    $("#changeOrderForm [name='ceoNeedStatus']").val(proStatusText[1]);
                } else {
                    $("#changeOrderForm [name='ceoNeedStatus']").val(proStatusText[proStatus]);
                }
                break;
            }
        }
    }

    /**
     *@FunctionName: selectMode
     *@Description: 根据模式选择使用方式
     *@Author: 徐一贺
     *@CreateDate: 2020/4/24 13:51
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function selectMode() {
        findWarehouseList();
        loadDept();
    }

    $(function () {

        $("#proProductionStatus1").change(function () {
            $("input[name='proProductionStatusMultiple']").val($("#proProductionStatus1").val());
        });

        $("#btn_inventorySearch").on('click', function () {
            $("#btn_inventorySearch").prop('disabled', true).addClass('disabled');
            js.table.refresh(modalTable);
        });

        selectMode();
        //重置
        $("#btn_reset").on('click', function () {
            //JQuery清空表单内容
            $("#changeOrderForm")[0].reset();
            //bootstrapValidator清空重置验证提示状态
            $(".form-horizontal").data("bootstrapValidator").resetForm();
            js.modal.success("重置表单成功！");
        });
        $("#btn_verification").on('click', function () {
            //bootstrapValidator清空重置验证提示状态
            $(".form-horizontal").data("bootstrapValidator").resetForm();
            var bootstrapValidator = $("#changeOrderForm").data('bootstrapValidator');
            //手动触发验证
            bootstrapValidator.validate();
        })
        //保存
        $("#btn_save").on('click', function () {
            $("#btn_save").hide();
            var result = false;
            if ($("#changeOrderForm [name='ceoNeedNum']").val() == undefined || $("#changeOrderForm [name='ceoNeedNum']").val() == '') {
                js.modal.warning("请输入需求数量！");
                $("#btn_save").show();
                return;
            } else if (parseFloat($("#changeOrderForm [name='ceoNeedNum']").val()) > $("#changeOrderForm [name='ceoUseNum']").val()) {
                js.modal.warning("需求数量不可大于可用数量！");
                $("#btn_save").show();
                return;
            } else {
                if ($("#changeOrderForm [name='ceoNeedProCode']").val().toUpperCase() == $("#changeOrderForm [name='ceoUseProCode']").val().toUpperCase()) {
                    js.modal.warning("需求项目编号不可与挪用项目编号相同！");
                    $("#btn_save").show();
                    return;
                } else {
                    let formData = new FormData($("#changeOrderForm")[0])
                    js.validSubmit({
                        formId: "changeOrderForm",
                        url: ctx + "purchase/change/save",
                        data: formData,
                        success: function (result) {
                            $("#btn_save").show();
                            if (result.type == web_status.SUCCESS) {
                                window.history.back();
                            } else {
                                js.modal.warning(result.msg);
                            }
                        }
                    });
                }
                // var intervalId = window.setInterval(function () {
                //     if (js.validate.isValid("changeOrderForm")) {
                //         result = true;
                //     }
                //     if (result == true) {
                //
                //         window.clearInterval(intervalId);
                //     }
                // }, 500);
            }
        });


        // 验证初始化
        js.validate.init("changeOrderForm", {
            fields: {
                ceoNeedProCode: {
                    validators: {
                        notEmpty: {message: '请输入需求项目编号'},
                        threshold: 6, //有6字符以上才发送ajax请求，（input中输入一个字符，插件会向服务器发送一次，设置限制，6字符以上才开始）
                        callback: {
                            message: "项目号不存在",
                            callback: function (value, validator) {
                                var flag = false;
                                if (value.length >= 6) {
                                    $.ajax({
                                        url: ctx + 'purchase/change/codeExist', // 请求路径
                                        type: 'POST',
                                        async: false,	// 同步请求，必须是false
                                        data: {
                                            ceoNeedProCode: value // 请求参数
                                        },
                                        success: function (res) {
                                            flag = $.parseJSON(res).valid;
                                            if(flag==false){
                                                $("#btn_save").show();
                                            }
                                        }
                                    });
                                    return flag;
                                }

                            }
                        }
                    }
                },
                ceoNeedProName: {
                    validators: {
                        notEmpty: {
                            message: '请输入需求项目名称', callback: function (value, validator) {
                                $("#btn_save").show();
                            }
                        }
                    }
                },
                ceoNeedMatName: {
                    validators: {
                        notEmpty: {
                            message: '请输入需求物料描述', callback: function (value, validator) {
                                $("#btn_save").show();
                            }
                        }
                    }
                },
                ceoUseProCode: {
                    validators: {
                        notEmpty: {
                            message: '请输选择库存', callback: function (value, validator) {
                                $("#btn_save").show();
                            }
                        }
                    }
                },
                ceoUseProName: {
                    validators: {
                        notEmpty: {
                            message: '请输选择库存', callback: function (value, validator) {
                                $("#btn_save").show();
                            }
                        }
                    }
                },
                ceoUseMatName: {
                    validators: {
                        notEmpty: {
                            message: '请输选择库存', callback: function (value, validator) {
                                $("#btn_save").show();
                            }
                        }
                    }
                },
                ceoUseNum: {
                    validators: {
                        notEmpty: {
                            message: '请输选择库存', callback: function (value, validator) {
                                $("#btn_save").show();
                            }
                        }
                    }
                },
                // ceoNeedDepId: {validators: {notEmpty: {message: '请输选择使用部门'}}},
                // ceoUseDepId: {validators: {notEmpty: {message: '请输选择所在部门'}}},
                // ceoNeedStatus: {
                //     validators: {
                //         notEmpty: {message: '请输入需求项目生产状况'}
                //     }
                // },
                // ceoUseStatus: {
                //     validators: {
                //         notEmpty: {message: '请输入挪用项目生产状况'}
                //     }
                // }
            }
        });
    });
</script>
</body>
</html>
